package com.sm.controller.vod;

import com.sm.util.Msg;
import com.sm.vod.AliyunUpload;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wangpengliang
 * Date 2020/5/18 2:56 下午
 * Copyright (C) www.lovesfang.com
 */
@RestController
@RequestMapping("/vod")
public class VodController {

    /**
     * 获取播放凭证
     * @param videoId
     * @return
     */
    @GetMapping("/getPlayAuth")
    public Msg getPlayAuth(@RequestParam("videoId") String videoId){
        Map<String, Object> resultMap = AliyunUpload.getVideoPlayAuth(videoId);
        return Msg.success(resultMap);
    }


    /**
     * 获取上传图片凭证函数
     * @param title title标题
     * @return
     */
    @GetMapping("getImgAuth")
    public Msg getImgAuth(@RequestParam String title){
        Map<String, Object> resultMap = AliyunUpload.getImgUploadImage(title);
        return Msg.success(resultMap);
    }

    /**
     * 获取视频上传地址和凭证
     * @param fileName
     * @return
     */
    @GetMapping("/getUploadVideoAuth")
    public Msg createUploadVideo(@RequestParam("fileName") String fileName){
        Map<String, Object> params = new HashMap<>();
        params.put("title", fileName.substring(0,fileName.lastIndexOf(".")));
        params.put("fileName", fileName);
        Map<String, Object> resultMap = AliyunUpload.createUploadVideo(params);
        return Msg.success(resultMap);
    }

    /**
     * 刷新视频上传凭证
     * @param videoId
     * @return
     */
    @GetMapping("refreshUploadVideoAuth")
    public Msg refreshUploadVideo(@RequestParam String videoId) {
        Map<String, Object> resultMap = AliyunUpload.refreshUploadVideo(videoId);
        return Msg.success(resultMap);
    }
}

